package com.flex.mobile.dao.model;

import java.io.Serializable;

import com.flex.mobile.constant.OrderToDriverConst;
import com.flex.mobile.model.Location;

public class Extent implements Serializable {

	private static final long serialVersionUID = 1L;

	private double xmax;
	private double xmin;
	private double ymax;
	private double ymin;

	public Extent() {

	}

	public Extent(double xmax, double xmin, double ymax, double ymin) {
		this.xmax = xmax;
		this.xmin = xmin;
		this.ymax = ymax;
		this.ymin = ymin;
	}

	public double getWidth() {
		return xmax - xmin;
	}

	public double getHeight() {
		return ymax - ymin;
	}

	public double getXmax() {
		return xmax;
	}

	public void setXmax(double xmax) {
		this.xmax = xmax;
	}

	public double getXmin() {
		return xmin;
	}

	public void setXmin(double xmin) {
		this.xmin = xmin;
	}

	public double getYmax() {
		return ymax;
	}

	public void setYmax(double ymax) {
		this.ymax = ymax;
	}

	public double getYmin() {
		return ymin;
	}

	public void setYmin(double ymin) {
		this.ymin = ymin;
	}

	public static Extent getExtentByTolerance(Location location, double tolerance) {
		Extent extent = new Extent(location.getLon() + OrderToDriverConst.FIND_DRIVER_BUFFER, location.getLon() - OrderToDriverConst.FIND_DRIVER_BUFFER, location.getLat()
				+ OrderToDriverConst.FIND_DRIVER_BUFFER, location.getLat() - OrderToDriverConst.FIND_DRIVER_BUFFER);
		return extent;
	}

	public boolean contains(Location location) {
		if (location.getLon() > getXmin() && location.getLon() < getXmax() && location.getLat() > getYmin() && location.getLat() < getYmax()) {
			return true;
		}
		return false;
	}
}
